from selenium import webdriver

#定义工具类
from selenium.webdriver.common.by import By


class UtilsDriver:
    driver = None

#定义获取博客园web的浏览器驱动
    @classmethod
    def get_driver(cls):
        if cls.driver is None:
            cls.driver = webdriver.Chrome()
            cls.driver.maximize_window()
            cls.driver.get("https://www.cnblogs.com/")
        return cls.driver

#定义退出博客园web的浏览器驱动
    @classmethod
    def quit_driver(cls):
        if cls.driver is not None:
            cls.get_driver().quit()
            cls.driver = None

#封装一个方法判断元素是否存在
def is_exist(driver,text):
    xpath = "//*[contains(text(),'{}')]".format(text)
    try:
        return driver.find_element(By.XPATH,xpath)
    except Exception as e:
        return False





